package com.whu.gc.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.whu.pojo.Car;

import com.whu.gc.service.SearchCarService;


@Controller
@RequestMapping("car")
public class CarController {

	@Autowired
	SearchCarService searchCarService;
	
	@RequestMapping("/querycars")
	public ModelAndView querycars(Car car) throws Exception{
		//调用service查找 数据库，查询商品列表
		System.out.println(car.toString());
		List<Car> carList = new ArrayList<Car>();
		carList = searchCarService.selectByMessage(car);

		//返回ModelAndView
		ModelAndView modelAndView =  new ModelAndView();
		//相当 于request的setAttribut，在jsp页面中通过itemsList取数据
		modelAndView.addObject("carList", carList);
		System.out.println(carList);
		modelAndView.setViewName("search");
		
		return modelAndView;
	}
	@RequestMapping("/querycarsbykey")
	public ModelAndView querycarsbykey(String key) throws Exception{
		//调用service查找 数据库，查询商品列表
		System.out.println(key);
		List<Car> carList = new ArrayList<Car>();
		carList = searchCarService.selectByKey(key);

		//返回ModelAndView
		ModelAndView modelAndView =  new ModelAndView();
		//相当 于request的setAttribut，在jsp页面中通过itemsList取数据
		modelAndView.addObject("carList", carList);
		System.out.println(carList);
		modelAndView.setViewName("search");
		
		return modelAndView;
	}

}